home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / doom / quake.zip / TORNADO.ZIP / WEAPONS.QC < prev    next >
Text File  |  1997-04-20  |  28KB  |  1,372 lines

  1. /*
  2. */
  3. void (entity targ, entity inflictor, entity attacker, float damage) T_Damage;
  4. void () player_run;
  5. void(entity bomb, entity attacker, float rad, entity ignore) T_RadiusDamage;
  6. void(vector org, vector vel, float damage) SpawnBlood;
  7. void() SuperDamageSound;
  8.  
  9. // STORM_BOMB
  10. void() W_LaunchStormBomb;
  11. // STORM_BOMB
  12.  
  13. // TORNADO_BOMB
  14. void() W_LaunchTornadoBomb;
  15. // TORNADO_BOMB
  16.  
  17. // called by worldspawn
  18. void() W_Precache =
  19. {
  20.     precache_sound ("weapons/r_exp3.wav");    // new rocket explosion
  21.     precache_sound ("weapons/rocket1i.wav");    // spike gun
  22.     precache_sound ("weapons/sgun1.wav");
  23.     precache_sound ("weapons/guncock.wav");    // player shotgun
  24.     precache_sound ("weapons/ric1.wav");    // ricochet (used in c code)
  25.     precache_sound ("weapons/ric2.wav");    // ricochet (used in c code)
  26.     precache_sound ("weapons/ric3.wav");    // ricochet (used in c code)
  27.     precache_sound ("weapons/spike2.wav");    // super spikes
  28.     precache_sound ("weapons/tink1.wav");    // spikes tink (used in c code)
  29.     precache_sound ("weapons/grenade.wav");    // grenade launcher
  30.     precache_sound ("weapons/bounce.wav");        // grenade bounce
  31.     precache_sound ("weapons/shotgn2.wav");    // super shotgun
  32. };
  33.  
  34. float() crandom =
  35. {
  36.     return 2*(random() - 0.5);
  37. };
  38.  
  39. /*
  40. ================
  41. W_FireAxe
  42. ================
  43. */
  44. void() W_FireAxe =
  45. {
  46.     local    vector    source;
  47.     local    vector    org;
  48.  
  49.     makevectors (self.v_angle);
  50.     source = self.origin + '0 0 16';
  51.     traceline (source, source + v_forward*64, FALSE, self);
  52.     if (trace_fraction == 1.0)
  53.         return;
  54.     
  55.     org = trace_endpos - v_forward*4;
  56.  
  57.     if (trace_ent.takedamage)
  58.     {
  59.         trace_ent.axhitme = 1;
  60.         SpawnBlood (org, '0 0 0', 20);
  61.         T_Damage (trace_ent, self, self, 20);
  62.     }
  63.     else
  64.     {    // hit wall
  65.         sound (self, CHAN_WEAPON, "player/axhit2.wav", 1, ATTN_NORM);
  66.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  67.         WriteByte (MSG_BROADCAST, TE_GUNSHOT);
  68.         WriteCoord (MSG_BROADCAST, org_x);
  69.         WriteCoord (MSG_BROADCAST, org_y);
  70.         WriteCoord (MSG_BROADCAST, org_z);
  71.     }
  72. };
  73.  
  74.  
  75. //============================================================================
  76.  
  77.  
  78. vector() wall_velocity =
  79. {
  80.     local vector    vel;
  81.     
  82.     vel = normalize (self.velocity);
  83.     vel = normalize(vel + v_up*(random()- 0.5) + v_right*(random()- 0.5));
  84.     vel = vel + 2*trace_plane_normal;
  85.     vel = vel * 200;
  86.     
  87.     return vel;
  88. };
  89.  
  90.  
  91. /*
  92. ================
  93. SpawnMeatSpray
  94. ================
  95. */
  96. void(vector org, vector vel) SpawnMeatSpray =
  97. {
  98.     local    entity missile, mpuff;
  99.     local    vector    org;
  100.  
  101.     missile = spawn ();
  102.     missile.owner = self;
  103.     missile.movetype = MOVETYPE_BOUNCE;
  104.     missile.solid = SOLID_NOT;
  105.  
  106.     makevectors (self.angles);
  107.  
  108.     missile.velocity = vel;
  109.     missile.velocity_z = missile.velocity_z + 250 + 50*random();
  110.  
  111.     missile.avelocity = '3000 1000 2000';
  112.     
  113. // set missile duration
  114.     missile.nextthink = time + 1;
  115.     missile.think = SUB_Remove;
  116.  
  117.     setmodel (missile, "progs/zom_gib.mdl");
  118.     setsize (missile, '0 0 0', '0 0 0');        
  119.     setorigin (missile, org);
  120. };
  121.  
  122. /*
  123. ================
  124. SpawnBlood
  125. ================
  126. */
  127. void(vector org, vector vel, float damage) SpawnBlood =
  128. {
  129.     particle (org, vel*0.1, 73, damage*2);
  130. };
  131.  
  132. /*
  133. ================
  134. spawn_touchblood
  135. ================
  136. */
  137. void(float damage) spawn_touchblood =
  138. {
  139.     local vector    vel;
  140.  
  141.     vel = wall_velocity () * 0.2;
  142.     SpawnBlood (self.origin + vel*0.01, vel, damage);
  143. };
  144.  
  145.  
  146. /*
  147. ================
  148. SpawnChunk
  149. ================
  150. */
  151. void(vector org, vector vel) SpawnChunk =
  152. {
  153.     particle (org, vel*0.02, 0, 10);
  154. };
  155.  
  156. /*
  157. ==============================================================================
  158.  
  159. MULTI-DAMAGE
  160.  
  161. Collects multiple small damages into a single damage
  162.  
  163. ==============================================================================
  164. */
  165.  
  166. entity    multi_ent;
  167. float    multi_damage;
  168.  
  169. void() ClearMultiDamage =
  170. {
  171.     multi_ent = world;
  172.     multi_damage = 0;
  173. };
  174.  
  175. void() ApplyMultiDamage =
  176. {
  177.     if (!multi_ent)
  178.         return;
  179.     T_Damage (multi_ent, self, self, multi_damage);
  180. };
  181.  
  182. void(entity hit, float damage) AddMultiDamage =
  183. {
  184.     if (!hit)
  185.         return;
  186.     
  187.     if (hit != multi_ent)
  188.     {
  189.         ApplyMultiDamage ();
  190.         multi_damage = damage;
  191.         multi_ent = hit;
  192.     }
  193.     else
  194.         multi_damage = multi_damage + damage;
  195. };
  196.  
  197. /*
  198. ==============================================================================
  199.  
  200. BULLETS
  201.  
  202. ==============================================================================
  203. */
  204.  
  205. /*
  206. ================
  207. TraceAttack
  208. ================
  209. */
  210. void(float damage, vector dir) TraceAttack =
  211. {
  212.     local    vector    vel, org;
  213.     
  214.     vel = normalize(dir + v_up*crandom() + v_right*crandom());
  215.     vel = vel + 2*trace_plane_normal;
  216.     vel = vel * 200;
  217.  
  218.     org = trace_endpos - dir*4;
  219.  
  220.     if (trace_ent.takedamage)
  221.     {
  222.         SpawnBlood (org, vel*0.2, damage);
  223.         AddMultiDamage (trace_ent, damage);
  224.     }
  225.     else
  226.     {
  227.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  228.         WriteByte (MSG_BROADCAST, TE_GUNSHOT);
  229.         WriteCoord (MSG_BROADCAST, org_x);
  230.         WriteCoord (MSG_BROADCAST, org_y);
  231.         WriteCoord (MSG_BROADCAST, org_z);
  232.     }
  233. };
  234.  
  235. /*
  236. ================
  237. FireBullets
  238.  
  239. Used by shotgun, super shotgun, and enemy soldier firing
  240. Go to the trouble of combining multiple pellets into a single damage call.
  241. ================
  242. */
  243. void(float shotcount, vector dir, vector spread) FireBullets =
  244. {
  245.     local    vector direction;
  246.     local    vector    src;
  247.     
  248.     makevectors(self.v_angle);
  249.  
  250.     src = self.origin + v_forward*10;
  251.     src_z = self.absmin_z + self.size_z * 0.7;
  252.  
  253.     ClearMultiDamage ();
  254.     while (shotcount > 0)
  255.     {
  256.         direction = dir + crandom()*spread_x*v_right + crandom()*spread_y*v_up;
  257.  
  258.         traceline (src, src + direction*2048, FALSE, self);
  259.         if (trace_fraction != 1.0)
  260.             TraceAttack (4, direction);
  261.  
  262.         shotcount = shotcount - 1;
  263.     }
  264.     ApplyMultiDamage ();
  265. };
  266.  
  267. /*
  268. ================
  269. W_FireShotgun
  270. ================
  271. */
  272. void() W_FireShotgun =
  273. {
  274.     local vector dir;
  275.  
  276.     sound (self, CHAN_WEAPON, "weapons/guncock.wav", 1, ATTN_NORM);    
  277.  
  278.     self.punchangle_x = -2;
  279.     
  280.     self.currentammo = self.ammo_shells = self.ammo_shells - 1;
  281.     dir = aim (self, 100000);
  282.     FireBullets (6, dir, '0.04 0.04 0');
  283. };
  284.  
  285.  
  286. /*
  287. ================
  288. W_FireSuperShotgun
  289. ================
  290. */
  291. void() W_FireSuperShotgun =
  292. {
  293.     local vector dir;
  294.  
  295.     if (self.currentammo == 1)
  296.     {
  297.         W_FireShotgun ();
  298.         return;
  299.     }
  300.         
  301.     sound (self ,CHAN_WEAPON, "weapons/shotgn2.wav", 1, ATTN_NORM);    
  302.  
  303.     self.punchangle_x = -4;
  304.     
  305.     self.currentammo = self.ammo_shells = self.ammo_shells - 2;
  306.     dir = aim (self, 100000);
  307.     FireBullets (14, dir, '0.14 0.08 0');
  308. };
  309.  
  310.  
  311. /*
  312. ==============================================================================
  313.  
  314. ROCKETS
  315.  
  316. ==============================================================================
  317. */
  318.  
  319. void()    s_explode1    =    [0,        s_explode2] {};
  320. void()    s_explode2    =    [1,        s_explode3] {};
  321. void()    s_explode3    =    [2,        s_explode4] {};
  322. void()    s_explode4    =    [3,        s_explode5] {};
  323. void()    s_explode5    =    [4,        s_explode6] {};
  324. void()    s_explode6    =    [5,        SUB_Remove] {};
  325.  
  326. void() BecomeExplosion =
  327. {
  328.     self.movetype = MOVETYPE_NONE;
  329.     self.velocity = '0 0 0';
  330.     self.touch = SUB_Null;
  331.     setmodel (self, "progs/s_explod.spr");
  332.     self.solid = SOLID_NOT;
  333.     s_explode1 ();
  334. };
  335.  
  336. void() T_MissileTouch =
  337. {
  338.     local float    damg;
  339.  
  340.     if (other == self.owner)
  341.         return;        // don't explode on owner
  342.  
  343.     if (pointcontents(self.origin) == CONTENT_SKY)
  344.     {
  345.         remove(self);
  346.         return;
  347.     }
  348.  
  349.     damg = 100 + random()*20;
  350.     
  351.     if (other.health)
  352.     {
  353.         if (other.classname == "monster_shambler")
  354.             damg = damg * 0.5;    // mostly immune
  355.         T_Damage (other, self, self.owner, damg );
  356.     }
  357.  
  358.     // don't do radius damage to the other, because all the damage
  359.     // was done in the impact
  360.     T_RadiusDamage (self, self.owner, 120, other);
  361.  
  362. //    sound (self, CHAN_WEAPON, "weapons/r_exp3.wav", 1, ATTN_NORM);
  363.     self.origin = self.origin - 8*normalize(self.velocity);
  364.  
  365.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  366.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  367.     WriteCoord (MSG_BROADCAST, self.origin_x);
  368.     WriteCoord (MSG_BROADCAST, self.origin_y);
  369.     WriteCoord (MSG_BROADCAST, self.origin_z);
  370.  
  371.     BecomeExplosion ();
  372. };
  373.  
  374.  
  375.  
  376. /*
  377. ================
  378. W_FireRocket
  379. ================
  380. */
  381. void() W_FireRocket =
  382. {
  383.     local    entity missile, mpuff;
  384.     
  385.     self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  386.     
  387.     sound (self, CHAN_WEAPON, "weapons/sgun1.wav", 1, ATTN_NORM);
  388.  
  389.     self.punchangle_x = -2;
  390.  
  391.     missile = spawn ();
  392.     missile.owner = self;
  393.     missile.movetype = MOVETYPE_FLYMISSILE;
  394.     missile.solid = SOLID_BBOX;
  395.     missile.classname = "missile";
  396.         
  397. // set missile speed    
  398.  
  399.     makevectors (self.v_angle);
  400.     missile.velocity = aim(self, 1000);
  401.     missile.velocity = missile.velocity * 1000;
  402.     missile.angles = vectoangles(missile.velocity);
  403.     
  404.     missile.touch = T_MissileTouch;
  405.     
  406. // set missile duration
  407.     missile.nextthink = time + 5;
  408.     missile.think = SUB_Remove;
  409.  
  410.     setmodel (missile, "progs/missile.mdl");
  411.     setsize (missile, '0 0 0', '0 0 0');        
  412.     setorigin (missile, self.origin + v_forward*8 + '0 0 16');
  413. };
  414.  
  415. /*
  416. ===============================================================================
  417.  
  418. LIGHTNING
  419.  
  420. ===============================================================================
  421. */
  422.  
  423. /*
  424. =================
  425. LightningDamage
  426. =================
  427. */
  428. void(vector p1, vector p2, entity from, float damage) LightningDamage =
  429. {
  430.     local entity        e1, e2;
  431.     local vector        f;
  432.     
  433.     f = p2 - p1;
  434.     normalize (f);
  435.     f_x = 0 - f_y;
  436.     f_y = f_x;
  437.     f_z = 0;
  438.     f = f*16;
  439.  
  440.     e1 = e2 = world;
  441.  
  442.     traceline (p1, p2, FALSE, self);
  443.     if (trace_ent.takedamage)
  444.     {
  445.         particle (trace_endpos, '0 0 100', 225, damage*4);
  446.         T_Damage (trace_ent, from, from, damage);
  447.         if (self.classname == "player")
  448.         {
  449.             if (other.classname == "player")
  450.                 trace_ent.velocity_z = trace_ent.velocity_z + 400;
  451.         }
  452.     }
  453.     e1 = trace_ent;
  454.  
  455.     traceline (p1 + f, p2 + f, FALSE, self);
  456.     if (trace_ent != e1 && trace_ent.takedamage)
  457.     {
  458.         particle (trace_endpos, '0 0 100', 225, damage*4);
  459.         T_Damage (trace_ent, from, from, damage);
  460.     }
  461.     e2 = trace_ent;
  462.  
  463.     traceline (p1 - f, p2 - f, FALSE, self);
  464.     if (trace_ent != e1 && trace_ent != e2 && trace_ent.takedamage)
  465.     {
  466.         particle (trace_endpos, '0 0 100', 225, damage*4);
  467.         T_Damage (trace_ent, from, from, damage);
  468.     }
  469. };
  470.  
  471.  
  472. void() W_FireLightning =
  473. {
  474.     local    vector        org;
  475.     local    float        cells;
  476.  
  477.     if (self.ammo_cells < 1)
  478.     {
  479.         self.weapon = W_BestWeapon ();
  480.         W_SetCurrentAmmo ();
  481.         return;
  482.     }
  483.  
  484. // explode if under water
  485.     if (self.waterlevel > 1)
  486.     {
  487.         cells = self.ammo_cells;
  488.         self.ammo_cells = 0;
  489.         W_SetCurrentAmmo ();
  490.         T_RadiusDamage (self, self, 35*cells, world);
  491.         return;
  492.     }
  493.  
  494.     if (self.t_width < time)
  495.     {
  496.         sound (self, CHAN_WEAPON, "weapons/lhit.wav", 1, ATTN_NORM);
  497.         self.t_width = time + 0.6;
  498.     }
  499.     self.punchangle_x = -2;
  500.  
  501.     self.currentammo = self.ammo_cells = self.ammo_cells - 1;
  502.  
  503.     org = self.origin + '0 0 16';
  504.     
  505.     traceline (org, org + v_forward*600, TRUE, self);
  506.  
  507.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  508.     WriteByte (MSG_BROADCAST, TE_LIGHTNING2);
  509.     WriteEntity (MSG_BROADCAST, self);
  510.     WriteCoord (MSG_BROADCAST, org_x);
  511.     WriteCoord (MSG_BROADCAST, org_y);
  512.     WriteCoord (MSG_BROADCAST, org_z);
  513.     WriteCoord (MSG_BROADCAST, trace_endpos_x);
  514.     WriteCoord (MSG_BROADCAST, trace_endpos_y);
  515.     WriteCoord (MSG_BROADCAST, trace_endpos_z);
  516.  
  517.     LightningDamage (self.origin, trace_endpos + v_forward*4, self, 30);
  518. };
  519.  
  520.  
  521. //=============================================================================
  522.  
  523.  
  524. void() GrenadeExplode =
  525. {
  526.     T_RadiusDamage (self, self.owner, 120, world);
  527.  
  528.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  529.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  530.     WriteCoord (MSG_BROADCAST, self.origin_x);
  531.     WriteCoord (MSG_BROADCAST, self.origin_y);
  532.     WriteCoord (MSG_BROADCAST, self.origin_z);
  533.  
  534.     BecomeExplosion ();
  535. };
  536.  
  537. void() GrenadeTouch =
  538. {
  539.     if (other == self.owner)
  540.         return;        // don't explode on owner
  541.     if (other.takedamage == DAMAGE_AIM)
  542.     {
  543.         GrenadeExplode();
  544.         return;
  545.     }
  546.     sound (self, CHAN_WEAPON, "weapons/bounce.wav", 1, ATTN_NORM);    // bounce sound
  547.     if (self.velocity == '0 0 0')
  548.         self.avelocity = '0 0 0';
  549. };
  550.  
  551. /*
  552. ================
  553. W_FireGrenade
  554. ================
  555. */
  556. void() W_FireGrenade =
  557. {
  558.     local    entity missile, mpuff;
  559.     
  560.     self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  561.     
  562.     sound (self, CHAN_WEAPON, "weapons/grenade.wav", 1, ATTN_NORM);
  563.  
  564.     self.punchangle_x = -2;
  565.  
  566.     missile = spawn ();
  567.     missile.owner = self;
  568.     missile.movetype = MOVETYPE_BOUNCE;
  569.     missile.solid = SOLID_BBOX;
  570.     missile.classname = "grenade";
  571.         
  572. // set missile speed    
  573.  
  574.     makevectors (self.v_angle);
  575.  
  576.     if (self.v_angle_x)
  577.         missile.velocity = v_forward*600 + v_up * 200 + crandom()*v_right*10 + crandom()*v_up*10;
  578.     else
  579.     {
  580.         missile.velocity = aim(self, 10000);
  581.         missile.velocity = missile.velocity * 600;
  582.         missile.velocity_z = 200;
  583.     }
  584.  
  585.     missile.avelocity = '300 300 300';
  586.  
  587.     missile.angles = vectoangles(missile.velocity);
  588.     
  589.     missile.touch = GrenadeTouch;
  590.     
  591. // set missile duration
  592.     missile.nextthink = time + 2.5;
  593.     missile.think = GrenadeExplode;
  594.  
  595.     setmodel (missile, "progs/grenade.mdl");
  596.     setsize (missile, '0 0 0', '0 0 0');        
  597.     setorigin (missile, self.origin);
  598. };
  599.  
  600.  
  601. //=============================================================================
  602.  
  603. void() spike_touch;
  604. void() superspike_touch;
  605.  
  606.  
  607. /*
  608. ===============
  609. launch_spike
  610.  
  611. Used for both the player and the ogre
  612. ===============
  613. */
  614. void(vector org, vector dir) launch_spike =
  615. {
  616.     newmis = spawn ();
  617.     newmis.owner = self;
  618.     newmis.movetype = MOVETYPE_FLYMISSILE;
  619.     newmis.solid = SOLID_BBOX;
  620.  
  621.     newmis.angles = vectoangles(dir);
  622.     
  623.     newmis.touch = spike_touch;
  624.     newmis.classname = "spike";
  625.     newmis.think = SUB_Remove;
  626.     newmis.nextthink = time + 6;
  627.     setmodel (newmis, "progs/spike.mdl");
  628.     setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);        
  629.     setorigin (newmis, org);
  630.  
  631.     newmis.velocity = dir * 1000;
  632. };
  633.  
  634. void() W_FireSuperSpikes =
  635. {
  636.     local vector    dir;
  637.     local entity    old;
  638.     
  639.     sound (self, CHAN_WEAPON, "weapons/spike2.wav", 1, ATTN_NORM);
  640.     self.attack_finished = time + 0.2;
  641.     self.currentammo = self.ammo_nails = self.ammo_nails - 2;
  642.     dir = aim (self, 1000);
  643.     launch_spike (self.origin + '0 0 16', dir);
  644.     newmis.touch = superspike_touch;
  645.     setmodel (newmis, "progs/s_spike.mdl");
  646.     setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);        
  647.     self.punchangle_x = -2;
  648. };
  649.  
  650. void(float ox) W_FireSpikes =
  651. {
  652.     local vector    dir;
  653.     local entity    old;
  654.     
  655.     makevectors (self.v_angle);
  656.     
  657.     if (self.ammo_nails >= 2 && self.weapon == IT_SUPER_NAILGUN)
  658.     {
  659.         W_FireSuperSpikes ();
  660.         return;
  661.     }
  662.  
  663.     if (self.ammo_nails < 1)
  664.     {
  665.         self.weapon = W_BestWeapon ();
  666.         W_SetCurrentAmmo ();
  667.         return;
  668.     }
  669.  
  670.     sound (self, CHAN_WEAPON, "weapons/rocket1i.wav", 1, ATTN_NORM);
  671.     self.attack_finished = time + 0.2;
  672.     self.currentammo = self.ammo_nails = self.ammo_nails - 1;
  673.     dir = aim (self, 1000);
  674.     launch_spike (self.origin + '0 0 16' + v_right*ox, dir);
  675.  
  676.     self.punchangle_x = -2;
  677. };
  678.  
  679.  
  680.  
  681. .float hit_z;
  682. void() spike_touch =
  683. {
  684. local float rand;
  685.     if (other == self.owner)
  686.         return;
  687.  
  688.     if (other.solid == SOLID_TRIGGER)
  689.         return;    // trigger field, do nothing
  690.  
  691.     if (pointcontents(self.origin) == CONTENT_SKY)
  692.     {
  693.         remove(self);
  694.         return;
  695.     }
  696.     
  697. // hit something that bleeds
  698.     if (other.takedamage)
  699.     {
  700.         spawn_touchblood (9);
  701.         T_Damage (other, self, self.owner, 9);
  702.     }
  703.     else
  704.     {
  705.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  706.         
  707.         if (self.classname == "wizspike")
  708.             WriteByte (MSG_BROADCAST, TE_WIZSPIKE);
  709.         else if (self.classname == "knightspike")
  710.             WriteByte (MSG_BROADCAST, TE_KNIGHTSPIKE);
  711.         else
  712.             WriteByte (MSG_BROADCAST, TE_SPIKE);
  713.         WriteCoord (MSG_BROADCAST, self.origin_x);
  714.         WriteCoord (MSG_BROADCAST, self.origin_y);
  715.         WriteCoord (MSG_BROADCAST, self.origin_z);
  716.     }
  717.  
  718.     remove(self);
  719.  
  720. };
  721.  
  722. void() superspike_touch =
  723. {
  724. local float rand;
  725.     if (other == self.owner)
  726.         return;
  727.  
  728.     if (other.solid == SOLID_TRIGGER)
  729.         return;    // trigger field, do nothing
  730.  
  731.     if (pointcontents(self.origin) == CONTENT_SKY)
  732.     {
  733.         remove(self);
  734.         return;
  735.     }
  736.     
  737. // hit something that bleeds
  738.     if (other.takedamage)
  739.     {
  740.         spawn_touchblood (18);
  741.         T_Damage (other, self, self.owner, 18);
  742.     }
  743.     else
  744.     {
  745.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  746.         WriteByte (MSG_BROADCAST, TE_SUPERSPIKE);
  747.         WriteCoord (MSG_BROADCAST, self.origin_x);
  748.         WriteCoord (MSG_BROADCAST, self.origin_y);
  749.         WriteCoord (MSG_BROADCAST, self.origin_z);
  750.     }
  751.  
  752.     remove(self);
  753.  
  754. };
  755.  
  756.  
  757. /*
  758. ===============================================================================
  759.  
  760. PLAYER WEAPON USE
  761.  
  762. ===============================================================================
  763. */
  764.  
  765. void() W_SetCurrentAmmo =
  766. {
  767.     player_run ();        // get out of any weapon firing states
  768.  
  769.     self.items = self.items - ( self.items & (IT_SHELLS | IT_NAILS | IT_ROCKETS | IT_CELLS) );
  770.     
  771.     if (self.weapon == IT_AXE)
  772.     {
  773.         self.currentammo = 0;
  774.         self.weaponmodel = "progs/v_axe.mdl";
  775.         self.weaponframe = 0;
  776.     }
  777.     else if (self.weapon == IT_SHOTGUN)
  778.     {
  779.         self.currentammo = self.ammo_shells;
  780.         self.weaponmodel = "progs/v_shot.mdl";
  781.         self.weaponframe = 0;
  782.         self.items = self.items | IT_SHELLS;
  783.     }
  784.     else if (self.weapon == IT_SUPER_SHOTGUN)
  785.     {
  786.         self.currentammo = self.ammo_shells;
  787.         self.weaponmodel = "progs/v_shot2.mdl";
  788.         self.weaponframe = 0;
  789.         self.items = self.items | IT_SHELLS;
  790.     }
  791.     else if (self.weapon == IT_NAILGUN)
  792.     {
  793.         self.currentammo = self.ammo_nails;
  794.         self.weaponmodel = "progs/v_nail.mdl";
  795.         self.weaponframe = 0;
  796.         self.items = self.items | IT_NAILS;
  797.     }
  798.     else if (self.weapon == IT_SUPER_NAILGUN)
  799.     {
  800.         self.currentammo = self.ammo_nails;
  801.         self.weaponmodel = "progs/v_nail2.mdl";
  802.         self.weaponframe = 0;
  803.         self.items = self.items | IT_NAILS;
  804.     }
  805. // STORM_BOMB
  806. //    else if (self.weapon == IT_GRENADE_LAUNCHER)
  807. //    else if ((self.weapon == IT_GRENADE_LAUNCHER) || (self.weapon == IT_STORM_BOMB))
  808. // TORNADO_BOMB
  809.     else if ((self.weapon == IT_GRENADE_LAUNCHER) || (self.weapon == IT_STORM_BOMB) || (self.weapon == IT_TORNADO_BOMB1) || (self.weapon == IT_TORNADO_BOMB2))
  810. // TORNADO_BOMB
  811. // STORM_BOMB    
  812.  
  813.     {
  814.         self.currentammo = self.ammo_rockets;
  815.         self.weaponmodel = "progs/v_rock.mdl";
  816.         self.weaponframe = 0;
  817.         self.items = self.items | IT_ROCKETS;
  818.     }
  819.     else if (self.weapon == IT_ROCKET_LAUNCHER)
  820.     {
  821.         self.currentammo = self.ammo_rockets;
  822.         self.weaponmodel = "progs/v_rock2.mdl";
  823.         self.weaponframe = 0;
  824.         self.items = self.items | IT_ROCKETS;
  825.     }
  826.     else if (self.weapon == IT_LIGHTNING)
  827.     {
  828.         self.currentammo = self.ammo_cells;
  829.         self.weaponmodel = "progs/v_light.mdl";
  830.         self.weaponframe = 0;
  831.         self.items = self.items | IT_CELLS;
  832.     }
  833.     else
  834.     {
  835.         self.currentammo = 0;
  836.         self.weaponmodel = "";
  837.         self.weaponframe = 0;
  838.     }
  839. };
  840.  
  841. float() W_BestWeapon =
  842. {
  843.     local    float    it;
  844.     
  845.     it = self.items;
  846.  
  847.     if (self.waterlevel <= 1 && self.ammo_cells >= 1 && (it & IT_LIGHTNING) )
  848.             return IT_LIGHTNING;
  849.     if(self.ammo_nails >= 2 && (it & IT_SUPER_NAILGUN) )
  850.         return IT_SUPER_NAILGUN;
  851.     if(self.ammo_shells >= 2 && (it & IT_SUPER_SHOTGUN) )
  852.         return IT_SUPER_SHOTGUN;
  853.     if(self.ammo_nails >= 1 && (it & IT_NAILGUN) )
  854.         return IT_NAILGUN;
  855.     if(self.ammo_shells >= 1 && (it & IT_SHOTGUN) )
  856.         return IT_SHOTGUN;
  857.     return IT_AXE;
  858. };
  859.  
  860. float() W_CheckNoAmmo =
  861. {
  862.     if (self.currentammo > 0)
  863.         return TRUE;
  864.  
  865.     if (self.weapon == IT_AXE)
  866.         return TRUE;
  867.     
  868.     self.weapon = W_BestWeapon ();
  869.  
  870.     W_SetCurrentAmmo ();
  871.     
  872. // drop the weapon down
  873.     return FALSE;
  874. };
  875.  
  876. /*
  877. ============
  878. W_Attack
  879.  
  880. An attack impulse can be triggered now
  881. ============
  882. */
  883. void()    player_axe1;
  884. void()    player_axeb1;
  885. void()    player_axec1;
  886. void()    player_axed1;
  887. void()    player_shot1;
  888. void()    player_nail1;
  889. void()    player_light1;
  890. void()    player_rocket1;
  891.  
  892. void() W_Attack =
  893. {
  894.     local    float    r;
  895.  
  896.     if (!W_CheckNoAmmo ())
  897.         return;
  898.  
  899.     makevectors    (self.v_angle);            // calculate forward angle for velocity
  900.     self.show_hostile = time + 1;    // wake monsters up
  901.  
  902.     if (self.weapon == IT_AXE)
  903.     {
  904.         sound (self, CHAN_WEAPON, "weapons/ax1.wav", 1, ATTN_NORM);
  905.         r = random();
  906.         if (r < 0.25)
  907.             player_axe1 ();
  908.         else if (r<0.5)
  909.             player_axeb1 ();
  910.         else if (r<0.75)
  911.             player_axec1 ();
  912.         else
  913.             player_axed1 ();
  914.         self.attack_finished = time + 0.5;
  915.     }
  916.     else if (self.weapon == IT_SHOTGUN)
  917.     {
  918.         player_shot1 ();
  919.         W_FireShotgun ();
  920.         self.attack_finished = time + 0.5;
  921.     }
  922.     else if (self.weapon == IT_SUPER_SHOTGUN)
  923.     {
  924.         player_shot1 ();
  925.         W_FireSuperShotgun ();
  926.         self.attack_finished = time + 0.7;
  927.     }
  928.     else if (self.weapon == IT_NAILGUN)
  929.     {
  930.         player_nail1 ();
  931.     }
  932.     else if (self.weapon == IT_SUPER_NAILGUN)
  933.     {
  934.         player_nail1 ();
  935.     }
  936.     else if (self.weapon == IT_GRENADE_LAUNCHER)
  937.     {
  938.         player_rocket1();
  939.         W_FireGrenade();
  940.         self.attack_finished = time + 0.6;
  941.     }
  942.     else if (self.weapon == IT_ROCKET_LAUNCHER)
  943.     {
  944.         player_rocket1();
  945.         W_FireRocket();
  946.         self.attack_finished = time + 0.8;
  947.     }
  948.     else if (self.weapon == IT_LIGHTNING)
  949.     {
  950.         player_light1();
  951.         self.attack_finished = time + 0.1;
  952.         sound (self, CHAN_AUTO, "weapons/lstart.wav", 1, ATTN_NORM);
  953.     }
  954. // STORM_BOMB
  955.     else if (self.weapon == IT_STORM_BOMB)
  956.     {
  957.         W_LaunchStormBomb();
  958.         //self.attack_finished = time + 0.8;
  959.         self.attack_finished = time + 1.1;
  960.     }
  961. // STORM_BOMB
  962.  
  963. // TORNADO_BOMB
  964.     else if ((self.weapon == IT_TORNADO_BOMB1) || (self.weapon == IT_TORNADO_BOMB2))
  965.     {
  966.         W_LaunchTornadoBomb();
  967.         // self.attack_finished = time + 0.8;
  968.         self.attack_finished = time + 1.5;
  969.     }
  970. // TORNADO_BOMB
  971.  
  972. };
  973.  
  974. /*
  975. ============
  976. W_ChangeWeapon
  977.  
  978. ============
  979. */
  980. void() W_ChangeWeapon =
  981. {
  982.     local    float    it, am, fl;
  983.     
  984.     it = self.items;
  985.     am = 0;
  986.     
  987.     if (self.impulse == 1)
  988.     {
  989.         fl = IT_AXE;
  990.     }
  991.     else if (self.impulse == 2)
  992.     {
  993.         fl = IT_SHOTGUN;
  994.         if (self.ammo_shells < 1)
  995.             am = 1;
  996.     }
  997.     else if (self.impulse == 3)
  998.     {
  999.         fl = IT_SUPER_SHOTGUN;
  1000.         if (self.ammo_shells < 2)
  1001.             am = 1;
  1002.     }        
  1003.     else if (self.impulse == 4)
  1004.     {
  1005.         fl = IT_NAILGUN;
  1006.         if (self.ammo_nails < 1)
  1007.             am = 1;
  1008.     }
  1009.     else if (self.impulse == 5)
  1010.     {
  1011.         fl = IT_SUPER_NAILGUN;
  1012.         if (self.ammo_nails < 2)
  1013.             am = 1;
  1014.     }
  1015.     else if (self.impulse == 6)
  1016.  
  1017. // STORM_BOMB
  1018. /*
  1019.     {
  1020.         fl = IT_GRENADE_LAUNCHER;
  1021.         if (self.ammo_rockets < 1)
  1022.             am = 1;
  1023.     }         
  1024. */    
  1025.     {
  1026.         if (self.weapon == IT_GRENADE_LAUNCHER)
  1027.         { 
  1028.             self.weapon = IT_STORM_BOMB;
  1029.             centerprint(self,"Storm Bomb mode\n");
  1030.             return;
  1031.         } 
  1032.  
  1033. // TORNADO_BOMB - mode 1
  1034.         if (self.weapon == IT_STORM_BOMB)
  1035.         { 
  1036.             self.weapon = IT_TORNADO_BOMB1;
  1037.             centerprint(self,"Tornado Bomb mode 1\n");
  1038.             TornadoBombMode = 1;
  1039.             return;
  1040.         } 
  1041. // TORNADO_BOMB - mode 1
  1042.  
  1043. // TORNADO_BOMB - mode 2
  1044.         if (self.weapon == IT_TORNADO_BOMB1)
  1045.         { 
  1046.             self.weapon = IT_TORNADO_BOMB2;
  1047.             centerprint(self,"Tornado Bomb mode 2\n");
  1048.             TornadoBombMode = 2;
  1049.             return;
  1050.         } 
  1051. // TORNADO_BOMB - mode 2
  1052.  
  1053.         fl = IT_GRENADE_LAUNCHER;
  1054.         if (self.ammo_rockets < 1)
  1055.             am = 1;
  1056.         if (!am) centerprint(self,"Grenade Launcher Mode\n");
  1057.     }
  1058. // STORM_BOMB 
  1059.  
  1060.     else if (self.impulse == 7)
  1061.     {
  1062.         fl = IT_ROCKET_LAUNCHER;
  1063.         if (self.ammo_rockets < 1)
  1064.             am = 1;
  1065.     }
  1066.     else if (self.impulse == 8)
  1067.     {
  1068.         fl = IT_LIGHTNING;
  1069.         if (self.ammo_cells < 1)
  1070.             am = 1;
  1071.     }
  1072.  
  1073.     self.impulse = 0;
  1074.     
  1075.     if (!(self.items & fl))
  1076.     {    // don't have the weapon or the ammo
  1077.         sprint (self, "no weapon.\n");
  1078.         return;
  1079.     }
  1080.     
  1081.     if (am)
  1082.     {    // don't have the ammo
  1083.         sprint (self, "not enough ammo.\n");
  1084.         return;
  1085.     }
  1086.  
  1087. //
  1088. // set weapon, set ammo
  1089. //
  1090.     self.weapon = fl;        
  1091.     W_SetCurrentAmmo ();
  1092. };
  1093.  
  1094. /*
  1095. ============
  1096. CheatCommand
  1097. ============
  1098. */
  1099. void() CheatCommand =
  1100. {
  1101.     if (deathmatch || coop)
  1102.         return;
  1103.  
  1104.     self.ammo_rockets = 100;
  1105.     self.ammo_nails = 200;
  1106.     self.ammo_shells = 100;
  1107.     self.items = self.items | 
  1108.         IT_AXE |
  1109.         IT_SHOTGUN |
  1110.         IT_SUPER_SHOTGUN |
  1111.         IT_NAILGUN |
  1112.         IT_SUPER_NAILGUN |
  1113.         IT_GRENADE_LAUNCHER |
  1114.         IT_ROCKET_LAUNCHER |
  1115.         IT_KEY1 | IT_KEY2;
  1116.  
  1117.     self.ammo_cells = 200;
  1118.     self.items = self.items | IT_LIGHTNING;
  1119.  
  1120.     self.weapon = IT_ROCKET_LAUNCHER;
  1121.     self.impulse = 0;
  1122.     W_SetCurrentAmmo ();
  1123. };
  1124.  
  1125. /*
  1126. ============
  1127. CycleWeaponCommand
  1128.  
  1129. Go to the next weapon with ammo
  1130. ============
  1131. */
  1132. void() CycleWeaponCommand =
  1133. {
  1134.     local    float    it, am;
  1135.     
  1136.     it = self.items;
  1137.     self.impulse = 0;
  1138.     
  1139.     while (1)
  1140.     {
  1141.         am = 0;
  1142.  
  1143.         if (self.weapon == IT_LIGHTNING)
  1144.         {
  1145.             self.weapon = IT_AXE;
  1146.         }
  1147.         else if (self.weapon == IT_AXE)
  1148.         {
  1149.             self.weapon = IT_SHOTGUN;
  1150.             if (self.ammo_shells < 1)
  1151.                 am = 1;
  1152.         }
  1153.         else if (self.weapon == IT_SHOTGUN)
  1154.         {
  1155.             self.weapon = IT_SUPER_SHOTGUN;
  1156.             if (self.ammo_shells < 2)
  1157.                 am = 1;
  1158.         }        
  1159.         else if (self.weapon == IT_SUPER_SHOTGUN)
  1160.         {
  1161.             self.weapon = IT_NAILGUN;
  1162.             if (self.ammo_nails < 1)
  1163.                 am = 1;
  1164.         }
  1165.         else if (self.weapon == IT_NAILGUN)
  1166.         {
  1167.             self.weapon = IT_SUPER_NAILGUN;
  1168.             if (self.ammo_nails < 2)
  1169.                 am = 1;
  1170.         }
  1171.         else if (self.weapon == IT_SUPER_NAILGUN)
  1172.         {
  1173.             self.weapon = IT_GRENADE_LAUNCHER;
  1174.             if (self.ammo_rockets < 1)
  1175.                 am = 1;
  1176.         }
  1177.  
  1178. // STORM_BOMB        
  1179. //        else if (self.weapon == IT_GRENADE_LAUNCHER)
  1180. //        else if ((self.weapon == IT_GRENADE_LAUNCHER) || (self.weapon == IT_STORM_BOMB))
  1181. // TORNADO_BOMB        
  1182.         else if ((self.weapon == IT_GRENADE_LAUNCHER) || (self.weapon == IT_STORM_BOMB) || (self.weapon == IT_TORNADO_BOMB1) || (self.weapon == IT_TORNADO_BOMB2))
  1183. // TORNADO_BOMB        
  1184. // STORM_BOMB
  1185.         
  1186.         {
  1187.             self.weapon = IT_ROCKET_LAUNCHER;
  1188.             if (self.ammo_rockets < 1)
  1189.                 am = 1;
  1190.         }
  1191.         else if (self.weapon == IT_ROCKET_LAUNCHER)
  1192.         {
  1193.             self.weapon = IT_LIGHTNING;
  1194.             if (self.ammo_cells < 1)
  1195.                 am = 1;
  1196.         }
  1197.     
  1198.         if ( (it & self.weapon) && am == 0)
  1199.         {
  1200.             W_SetCurrentAmmo ();
  1201.             return;
  1202.         }
  1203.     }
  1204.  
  1205. };
  1206.  
  1207. /*
  1208. ============
  1209. CycleWeaponReverseCommand
  1210.  
  1211. Go to the prev weapon with ammo
  1212. ============
  1213. */
  1214. void() CycleWeaponReverseCommand =
  1215. {
  1216.     local    float    it, am;
  1217.     
  1218.     it = self.items;
  1219.     self.impulse = 0;
  1220.  
  1221.     while (1)
  1222.     {
  1223.         am = 0;
  1224.  
  1225.         if (self.weapon == IT_LIGHTNING)
  1226.         {
  1227.             self.weapon = IT_ROCKET_LAUNCHER;
  1228.             if (self.ammo_rockets < 1)
  1229.                 am = 1;
  1230.         }
  1231.         else if (self.weapon == IT_ROCKET_LAUNCHER)
  1232.         {
  1233.             self.weapon = IT_GRENADE_LAUNCHER;
  1234.             if (self.ammo_rockets < 1)
  1235.                 am = 1;
  1236.         }
  1237.         else if (self.weapon == IT_GRENADE_LAUNCHER)
  1238.         {
  1239.             self.weapon = IT_SUPER_NAILGUN;
  1240.             if (self.ammo_nails < 2)
  1241.                 am = 1;
  1242.         }
  1243.         else if (self.weapon == IT_SUPER_NAILGUN)
  1244.         {
  1245.             self.weapon = IT_NAILGUN;
  1246.             if (self.ammo_nails < 1)
  1247.                 am = 1;
  1248.         }
  1249.         else if (self.weapon == IT_NAILGUN)
  1250.         {
  1251.             self.weapon = IT_SUPER_SHOTGUN;
  1252.             if (self.ammo_shells < 2)
  1253.                 am = 1;
  1254.         }        
  1255.         else if (self.weapon == IT_SUPER_SHOTGUN)
  1256.         {
  1257.             self.weapon = IT_SHOTGUN;
  1258.             if (self.ammo_shells < 1)
  1259.                 am = 1;
  1260.         }
  1261.         else if (self.weapon == IT_SHOTGUN)
  1262.         {
  1263.             self.weapon = IT_AXE;
  1264.         }
  1265.         else if (self.weapon == IT_AXE)
  1266.         {
  1267.             self.weapon = IT_LIGHTNING;
  1268.             if (self.ammo_cells < 1)
  1269.                 am = 1;
  1270.         }
  1271.     
  1272.         if ( (it & self.weapon) && am == 0)
  1273.         {
  1274.             W_SetCurrentAmmo ();
  1275.             return;
  1276.         }
  1277.     }
  1278.  
  1279. };
  1280.  
  1281. /*
  1282. ============
  1283. ServerflagsCommand
  1284.  
  1285. Just for development
  1286. ============
  1287. */
  1288. void() ServerflagsCommand =
  1289. {
  1290.     serverflags = serverflags * 2 + 1;
  1291. };
  1292.  
  1293. void() QuadCheat =
  1294. {
  1295.     if (deathmatch || coop)
  1296.         return;
  1297.     self.super_time = 1;
  1298.     self.super_damage_finished = time + 30;
  1299.     self.items = self.items | IT_QUAD;
  1300.     dprint ("quad cheat\n");
  1301. };
  1302.  
  1303. /*
  1304. ============
  1305. ImpulseCommands
  1306.  
  1307. ============
  1308. */
  1309. void() ImpulseCommands =
  1310. {
  1311.     if (self.impulse >= 1 && self.impulse <= 8)
  1312.         W_ChangeWeapon ();
  1313.  
  1314.     if (self.impulse == 9)
  1315.         CheatCommand ();
  1316.     if (self.impulse == 10)
  1317.         CycleWeaponCommand ();
  1318.     if (self.impulse == 11)
  1319.         ServerflagsCommand ();
  1320.     if (self.impulse == 12)
  1321.         CycleWeaponReverseCommand ();
  1322.  
  1323.     if (self.impulse == 255)
  1324.         QuadCheat ();
  1325.         
  1326.     self.impulse = 0;
  1327. };
  1328.  
  1329. /*
  1330. ============
  1331. W_WeaponFrame
  1332.  
  1333. Called every frame so impulse events can be handled as well as possible
  1334. ============
  1335. */
  1336. void() W_WeaponFrame =
  1337. {
  1338.     if (time < self.attack_finished)
  1339.         return;
  1340.  
  1341.     ImpulseCommands ();
  1342.     
  1343. // check for attack
  1344.     if (self.button0)
  1345.     {
  1346.         SuperDamageSound ();
  1347.         W_Attack ();
  1348.     }
  1349. };
  1350.  
  1351. /*
  1352. ========
  1353. SuperDamageSound
  1354.  
  1355. Plays sound if needed
  1356. ========
  1357. */
  1358. void() SuperDamageSound =
  1359. {
  1360.     if (self.super_damage_finished > time)
  1361.     {
  1362.         if (self.super_sound < time)
  1363.         {
  1364.             self.super_sound = time + 1;
  1365.             sound (self, CHAN_BODY, "items/damage3.wav", 1, ATTN_NORM);
  1366.         }
  1367.     }
  1368.     return;
  1369. };
  1370.  
  1371.  
  1372.